# 定义工具类
import os
import json
import time
from selenium import webdriver
class UtilsDriver():
    driver = None
    @classmethod
    def get_driver(cls):
        if cls.driver is None:
            cls.driver = webdriver.Chrome()
            cls.driver.maximize_window()
            cls.driver.implicitly_wait(10)
            cls.driver.get("http://tpshop-test.itheima.net/")
        return cls.driver

    @classmethod
    def quit_dirver(cls):
        if cls.driver is not None:
            cls.get_driver().quit()
            cls.driver = None


def get_msg():
    time.sleep(1)
    return UtilsDriver().get_driver().find_element_by_class_name("layui-layer-content").text

# 读取文件
# def get_case_data(filename):
#     with open(filename,encoding="utf-8") as f:
#         case_data = json.load(f)
#     list_case_data = []
#     for case in case_data:
#         # print(tuple(case.values()))
#         for i in case.values():
#             case_tuple = tuple(i.values())
#             # print(case_tuple)
#             list_case_data.append(case_tuple)
#     print(list_case_data)
#     return list_case_data

def get_case_data(filename):
    with open(filename,encoding="utf-8") as f:
        case_data = json.load(f)
    list_caes_data = []
    for case in case_data.values():
        list_caes_data.append(tuple(case.values()))
    print(list_caes_data)
    return list_caes_data



def get_path():
    BASE_DIR = os.path.dirname(os.path.abspath(__file__))
    # 当前文件的绝对路径，目录的名字
    # print(BASE_DIR)
    return BASE_DIR

if __name__ == '__main__':
    get_case_data(get_path()+"\data\login_data.json")


